﻿using System.Reflection;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace Serious
{
    public static class MouseStateExt
    {
        // this shouldnt really be used by the public
        public static ButtonState GetStateOf(this MouseState mouseState, Mbtn button)
        {
            string[] buttonPropertyNames = {
                "LeftButton",
                "RightButton",
                "MiddleButton",
                "XButton1",
                "XButton2",
            };
            string buttonPropertyName = buttonPropertyNames[(int)button];
            PropertyInfo propinfo = typeof(MouseState).GetProperty(buttonPropertyName);
            return (ButtonState)propinfo.GetValue(mouseState, null);
        }

        public static Index2 GetLocation(this MouseState mouseState)
        {
            return new Index2(mouseState.X, mouseState.Y);
        }

        public static bool IsButtonDown(this MouseState mouseState, Mbtn button)
        {
            return mouseState.GetStateOf(button) == ButtonState.Pressed;
        }
        public static bool IsButtonUp(this MouseState mouseState, Mbtn button)
        {
            return mouseState.GetStateOf(button) == ButtonState.Released;
        }
    }
}
